#!/usr/bin/php
<?php
// TODO: this no longer works, rewrite it for the new testing structure.


/**
 * tests the LaTeX formatter by formatting some code as LaTeX
 * then compiling it to pdf.
 * Requires pdflatex and the ability to call programs
 */
 

require_once dirname(__FILE__) . '/../../luminous.php';

$LUMINOUS_OUTPUT_FORMAT = 'latex';
$LUMINOUS_THEME = 'paradise';
$LUMINOUS_WRAP_WIDTH = 80;

$testfiles = glob(dirname(__FILE__) . '/../regressions/**');

$EXIT_STATUS = 0;

foreach($testfiles as $t)
{
  $ts = luminous_get_themes();
  $LUMINOUS_THEME = $ts[array_rand(luminous_get_themes())];
  $src = file_get_contents("$t");
  $lang = preg_replace('/.*\./', '', $t);
  
  $t = preg_replace('%.*/%', '', $t);
  $fmt = luminous($lang, $src, false);
  file_put_contents("filedump/$t.tex", $fmt);
  chdir('filedump');
  
  @system("pdflatex $t.tex >> /dev/null", $i);
  if ($i)
  {
    echo "latex formatter test failed on file $t, pdflatex exit status: $i\n";
    $EXIT_STATUS = 1;
  }
  chdir(getcwd() . '/../');
}

exit($EXIT_STATUS);
